<?php

namespace Admin\Controller;

class OrderController extends AdminController
{
	/**
	 * 订单列表
	 * @return [type] [description]
	 */
	public function showlist($range=0,$mobile=''){
		$data = D('Order') -> showlist($range,$mobile);
		//支付状态：已支付
		$where['status'] = 1;
		//今日订单数量
		$where['order'] = array('gt',strtotime(date('Y-m-d',time())));
		$total['todayorders'] = D('Order') -> where($where) -> count();
		//今日订单总额
		$total['todaytotal'] = D('Order') -> where($where) -> sum('price');
		$total['todaytotal'] = empty($total['todaytotal']) ? 0 : $total['todaytotal'];

		//本月订单数量
		$where['order'] = array('gt',strtotime(date('Y-m',time())));
		$total['monthorders'] = D('Order') -> where($where) -> count();
		//本月订单总额
		$total['monthtotal'] = D('Order') -> where($where) -> sum('price');
		$total['monthtotal'] = empty($total['monthtotal']) ? 0 : $total['monthtotal'];
				/* yxf 20171107 金额有几位小数就显示几位  S*/								$total['monthtotal'] =  floatval($total['monthtotal']);		$total['todaytotal'] =  floatval($total['todaytotal']);						foreach($data[0] as &$v){						$v['price'] =  floatval($v['price']);			$v['salary'] =  floatval($v['salary']);					}				unset($v);				/* yxf 20171107 金额有几位小数就显示几位  E*/	
		$this -> assign('data', $data);
		$this -> assign('total', $total);
		$this -> display();
	}

	/**
	 * 修改课程条目状态：未记录，已记录，删除
	 * @return [type] [description]
	 */
	// public function edit(){
	// 	if (IS_AJAX) {
	// 		$id = I('post.id');
	// 		$val = I('post.val');
	// 		$flag = I('post.flag');
	// 		if (D('Feedback') -> edit($id, $val, $flag)) {
	// 			$this -> ajaxReturn('操作成功');
	// 		} else {
	// 			$this -> ajaxReturn('出错了');
	// 		}
	// 	} elseif (IS_POST) {
	// 		// $ids = implode(',', I('post.ids'));
	// 		if (I('post.flag') == 'record') {
	// 			$val = 1;
	// 		}
	// 		if (I('post.flag') == 'status') {
	// 			$val = 2;
	// 		}
	// 		if (D('Feedback') -> edit(I('post.ids'), $val, I('post.flag'))) {
	// 			$this -> success('操作成功');
	// 		} else {
	// 			$this -> error('操作失败');
	// 		}
	// 	}
	// }
	public function index(){
		$data = D('Order') ->getAll();
		$this ->assign('data',$data);
		$this ->display();
	}
	/**
	 * 修改
	 */
	public function updateOrder(){
		$order = I('get.');
		$data  = D('Home/CourseRecord') ->ajaxCancel($order['order']);
		if($data){
			$this ->success('退订成功！',U('index'),1);
		}else{
			$this ->error('退订失败！',U('index'),1);
		}
	}
	public function ontOrder(){
		$order = I('get.order');
		if(D('Order') ->notCancel($order)){
			$this ->success('取消退订成功',U('index'));
		}else{
			$this ->success('取消退订失败',U('index'));
		}
	}
}
